//加载公共样式
require('../../assets/css/index.less')

//加载自己的样式
require('./mine.less')
// /* 引入字体图标 */
 require('../../assets/fonts/iconfont.css')

//服务器地址
const API = 'http://fitness.h5.itsource.cn:3701'
//引入axios工具函数
const request = require('../../utils/request')


//引入swiper
const mySwiper= require('swiper')
//引入tabbar渲染函数
const renderTabbar = require('../../utils/tabbar')


window.onload = () => {
/* 引入swiper的css样式 */
require('swiper/dist/css/swiper.min.css')

    let mySwiper = new Swiper('.swiper-container', {
        autoplay: 2000,//可选选项，自动滑动
        loop:true,
        pagination:'swiper-pagination'
    })


  //渲染tabbar
  renderTabbar('mine')

  //获取dom
  let avatar = document.querySelector('#avatar')
  const sign =document.querySelector('#sign')
  let num = document.querySelector('#num')
   let sumSports = document.querySelector('#sumSports')
   let weekSports = document.querySelector('#weekSports')
  // console.log(num);

  //获取用户信息
  function getUserInfo() {
    request.get('/api/user/info').then(res => {
      //1 解构数据
      let {errno, data} = res.data
      //2 判断
      if (errno === 0) {
        //3 处理业务逻辑
        // render(data)
        avatar.src = API + data.imgUrl
        sign.textContent= data.sign
        num.textContent =  data.clockCount
      }
    })
  }

  // //渲染数据
  // function render(data) {
  //   //图片渲染 服务器地址+相对路径+文件名
  //   avatar.src = API + data.imgUrl
  //   sign.textContent= data.sign
  //   num.textContent =  data.clockCount
  // }

  //初始化获取用户信息
  getUserInfo()

    //获取运动数据    
    function getSportsData() {
      request.get('/api/exercise').then(res => {
          console.log(res.data);
          //1 解构数据
          let { errno, data } = res.data
              //2 判断
          if (errno === 0) {
              //3 处理业务逻辑
              sumSports.textContent = data.sum7Duration
              weekSports.textContent = data.sum7Calorie
          }
      })

  }

  getSportsData()
}
